##########################
##########################
###Linear Models Script###
##########################
##########################
library(doBy)
library(ggplot2)
library(broom)
library(lubridate)
library(lfe)
library(stargazer)
library(DataCombine)
library(dplyr)
library(interplot)
library(survival)
library(MASS)
library(foreign)
###Import data
setwd("~/OneDrive - Indiana University/FromGoogle/GeolocatedDisease/")
full.1996.2019 <- read.csv("disease_conf_analysis_4_15_24.csv")

##############
###Baseline###
##############
######Armed conflict
####State
lm2.state<-felm(formula=acled_battle_state ~ 
                  log.nl + logged.pop +
                  p_anom+spei+outbreak+t_anom
                |gid+month|0|gid,
                data=full.1996.2019)
summary(lm2.state)
####Rebel
lm2.rebel<-felm(formula=acled_battle_rebel ~ 
                  log.nl + logged.pop +
                  p_anom+spei+outbreak+t_anom
                |gid+month|0|gid,
                data=full.1996.2019)
summary(lm2.rebel)

######Social conflict
###Political
lm2.mil.pol<-felm(formula=acled_battle_polmil ~ 
                    log.nl + logged.pop +
                    p_anom+spei+outbreak+t_anom
                  |gid+month|0|gid,
                  data=full.1996.2019)
summary(lm2.mil.pol)
###Identity
lm2.mil.id<-felm(formula=acled_battle_idmil ~ 
                   log.nl + logged.pop +
                   p_anom+spei+outbreak+t_anom
                 |gid+month|0|gid,
                 data=full.1996.2019)
summary(lm2.mil.id)

######################
###Country Controls###
######################
######Armed conflict
####State
lm3.state<-felm(formula=acled_battle_state ~ 
                  log.nl + logged.pop +
                  lagacled_battle_state + t  +
                  p_anom+spei+outbreak+t_anom+
                  logLifeExpectancy+GovEff+logGDPpc
                |gid+month|0|gid,
                data=full.1996.2019)
summary(lm3.state)
####Rebel
lm3.rebel<-felm(formula=acled_battle_rebel ~ 
                  log.nl + logged.pop +
                  lagacled_battle_rebel + t  +
                  p_anom+spei+outbreak+t_anom+
                  logLifeExpectancy+GovEff+logGDPpc
                |gid+month|0|gid,
                data=full.1996.2019)
summary(lm3.rebel)

######Social conflict
###Political
lm3.mil.pol<-felm(formula=acled_battle_polmil ~ 
                    log.nl + logged.pop +
                    lagacled_battle_polmil + t  +
                    p_anom+spei+outbreak+t_anom+
                    logLifeExpectancy+GovEff+logGDPpc
                  |gid+month|0|gid,
                  data=full.1996.2019)
summary(lm3.mil.pol)
###Identity
lm3.mil.id<-felm(formula=acled_battle_idmil ~ 
                   log.nl + logged.pop +
                   lagacled_battle_idmil + t  +
                   p_anom+spei+outbreak+t_anom+
                   logLifeExpectancy+GovEff+logGDPpc
                 |gid+month|0|gid,
                 data=full.1996.2019)
summary(lm3.mil.id)


###Export to LaTex Table 1
stargazer(lm2.mil.pol, lm3.mil.pol, lm2.mil.id, lm3.mil.id, ci = TRUE)


##Extract p-values

##State
#Baseline
summary(lm2.state)$coefficients[,4]
#Full
summary(lm3.state)$coefficients[,4]

##Rebel
#Baseline
summary(lm2.rebel)$coefficients[,4]
#Full
summary(lm3.rebel)$coefficients[,4]

##Pol mil
#Baseline
summary(lm2.mil.pol)$coefficients[,4]
#Full
summary(lm3.mil.pol)$coefficients[,4]

##Id mil
#Baseline
summary(lm2.mil.id)$coefficients[,4]
#Full
summary(lm3.mil.id)$coefficients[,4]




